//
//  NYAirlineCommitView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/8.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYAirlineCommitView.h"

@interface NYAirlineCommitView () <QMUITextViewDelegate>

@property (nonatomic, weak) id<NYAirlineCommitViewDelegate> delegate;

@property (nonatomic, strong) QMUITextView *textView;
@property (nonatomic, strong) QMUIButton *commitButton;

@end

@implementation NYAirlineCommitView

- (instancetype)initWithFrame:(CGRect)frame withDelegate:(id<NYAirlineCommitViewDelegate>)delegate {
    self = [super initWithFrame:frame];
    if (self) {
        _delegate = delegate;
        [self initUI];
    }
    return self;
}
#pragma mark - Intial Methods
- (void)initUI {
    
    [self setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:self.textView];
    [self addSubview:self.commitButton];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self).offset(10);
        make.bottom.equalTo(self.mas_bottom).offset(-55);
    }];
    
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(55);
        make.bottom.equalTo(self);
        make.right.equalTo(self.mas_right).offset(-15);
    }];
}

#pragma mark - Target Methods
- (void)commitButtonEvent:(QMUIButton *)sender {
    
    if (_textView.text.length == 0) {
        [NYTipClass showText:@"请您描述问题后再提交"];
        return;
    }
    if ([self.delegate respondsToSelector:@selector(submitTheQuestionToService:)]) {
        [self.delegate submitTheQuestionToService:_textView.text];
    }
}
#pragma mark - Public Methods

#pragma mark - Private Method

#pragma mark - External Delegate

#pragma mark - Setter Getter Methods
- (QMUITextView *)textView {
    if (!_textView) {
        _textView = [[QMUITextView alloc] init];
        _textView.backgroundColor = [UIColor whiteColor];
        _textView.placeholder = @"用文字描述你的问题...";
        _textView.placeholderColor = UIColorMakeWithHex(@"#D0D0D0");
        _textView.font = UIFontMake(14);
        _textView.delegate = self;
    }
    return _textView;
}
- (QMUIButton *)commitButton {
    if (!_commitButton) {
        _commitButton = [[QMUIButton alloc] qmui_initWithImage:nil title:@"提交"];
        [_commitButton setTitleColor:UIColorMakeWithHex(@"#3696FF") forState:0];
        _commitButton.backgroundColor = [UIColor whiteColor];
        _commitButton.titleLabel.font = UIFontMake(14);
        [_commitButton addTarget:self action:@selector(commitButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commitButton;
}
@end
